//
//  LRStatusListModel.swift
//  LRWeibo
//
//  Created by admin on 15/9/25.
//  Copyright © 2015年 懒人. All rights reserved.
//

import UIKit

/// 模型数据
class LRStatusListModel: NSObject {
    ///微博创建时间[http://open.weibo.com/wiki/2/statuses/home_timeline]
    var created_at: String?
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source:String?
    /// 微博作者的用户信息字段 详细
    var user: LRUserModel?
    /// 转发数
    var reposts_count:Int = 0
    /// 评论数
    var comments_count:Int = 0
    /// 微博配图ID。多图时返回多图ID，用来拼接图片url。用返回字段thumbnail_pic的地址配上该返回字段的图片ID
    var pic_urls: [[String: AnyObject]]?
    
    /// 用户头像
    var user_icon: NSURL{
    
        return NSURL(string: user?.profile_image_url ?? "")!
    }
    /// 会员等级
    var commonImage: UIImage?{
        if user?.mbrank > 0 && user?.mbrank < 7
        {
            return UIImage(named: "common_icon_membership_level\(user!.mbrank)")!
        }
        return UIImage(named: "common_icon_membership_expired")!
    }
    /// vip
    var vipImage: UIImage?{
        switch user!.verified_type
        {
        case -1: return nil
        case 0: return UIImage(named: "avatar_enterprise_vip")
        case 2,3,5: return UIImage(named: "avatar_grassroot")
        case 220: return UIImage(named: "avatar_vip")
        default :return nil
        }
    }
    
    /// 保存行高
    var heightForRow: CGFloat?
    
     // MARK: - 重构
    /// 初始化
    init(dict: [String: AnyObject])
    {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"
        {
            user = LRUserModel(dict: value as! [String: AnyObject])
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
 
}
